/*
 * @Author: wz
 * @Date: 2020-11-30 17:53:10
 * @LastEditors: wz
 * @LastEditTime: 2021-01-28 16:24:16
 * @Description:本地存储
 */
export const storage = {
    get(name) {
        let item = localStorage.getItem(name)
        try {
            return JSON.parse(item)
        } catch (e) {
            return item
        }
    },
    set(name, val) {
        let type = Object.prototype.toString.call(val).slice(8, -1)
        if (type === 'Object') {
            localStorage.setItem(name, JSON.stringify(val))
        } else {
            localStorage.setItem(name, val)
        }
    },
    remove(name) {
        localStorage.removeItem(name)
    },
    clear() {
        localStorage.clear()
    }
}

export const sessionStorage = {
    get(name) {
        let item = sessionStorage.getItem(name)
        if (item) {
            try {
                return JSON.parse(item)
            } catch (e) {
                return item
            }
        }
    },
    set(name, val) {
        let type = Object.prototype.toString.call(val).slice(8, -1)
        if (type === 'Object') {
            sessionStorage.setItem(name, JSON.stringify(val))
        } else {
            sessionStorage.setItem(name, val)
        }
    },
    remove(name) {
        sessionStorage.removeItem(name)
    },
    clear() {
        sessionStorage.clear()
    }
}
